package com.example.service;

import com.example.entity.Tip;
import com.example.mapper.TipMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TipService {
    @Resource
    private TipMapper tipMapper;

    public void add(Tip tip) {
        tipMapper.insert(tip);
    }

    public void deleteById(Integer id) {
        tipMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(Tip tip) {
        tipMapper.updateById(tip);
    }

    public Tip selectById(Integer id) {
        return tipMapper.selectById(id);
    }

    public List<Tip> selectAll(Tip tip) {
        return tipMapper.selectAll(tip);
    }

    public PageInfo<Tip> selectPage(Tip tip, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Tip> tipList = tipMapper.selectAll(tip);
        return PageInfo.of(tipList);
    }
}
